﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Product : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string maHang = "";
        string modelId = "";
        lbl_MaXe.Text = Request["Product"];

        string command = string.Format(@"
                                        SELECT * 
                                        FROM 
                                            ThongTinCoban tt ,
                                            NhienLieu nl,   
                                            HopSoChuyenDong hscd ,
                                            TuiKhiAnToan tk,
                                            PhanhDieuKhien pdk,
                                            ChongTrom ctr,
                                            thongsokhac tsk,
                                            ThongSoKiThuat tskt,
                                            KichThuocTrongLuong kttl,
                                            DongCo dc,
                                            PhanhLop pl,
                                            ChiTiet ct,
                                            gia g
                                        WHERE   
                                            tt.MaXe='{0}' 
                                            AND nl.MaXe=tt.MaXe 
                                            AND hscd.MaXe=tt.MaXe
                                            AND tk.MaXe=tt.MaXe
                                            AND pdk.MaXe=tt.MaXe
                                            AND ctr.MaXe=tt.MaXe
                                            AND tsk.MaXe=tt.MaXe
                                            AND tskt.MaXe=tt.MaXe
                                            AND kttl.MaXe=tt.MaXe
                                            AND dc.MaXe =tt.MaXe
                                            AND pl.MaXe=tt.MaXe
                                            AND ct.MaXe=tt.MaXe
                                            AND g.MaXe=tt.MaXe
                                        ", lbl_MaXe.Text);
        DataTable dt = DataBase.GetDataTable(command);
        foreach (DataRow dtr in dt.Rows)
        {
            // thong tin co ban
            lbl_TenXe.Text = dtr["TenXe"].ToString();
            lbl_NamSX.Text = dtr["NamSX"].ToString();
            lbl_Mau.Text = dtr["NgoaiThat"].ToString();
            lbl_TinhTrang.Text = dtr["TinhTrang"].ToString();
            maHang = dtr["MaHangXe"].ToString();
            modelId = dtr["ModelID"].ToString();
            lblModel.Text = dtr["DoiXe"].ToString();
            lblYear.Text = dtr["NamSX"].ToString();
            lblXuatXu.Text = dtr["XuatXu"].ToString();
            lblTinhTrang.Text = dtr["TinhTrang"].ToString();
            lblSoKm.Text = dtr["SoKM"].ToString();
            lblNoiThat.Text = dtr["NoiThat"].ToString();
            lblNgoaiThat.Text = dtr["NgoaiThat"].ToString();
            lblSoCua.Text = dtr["SoCua"].ToString();
            lblSoCho.Text = dtr["SoCHo"].ToString();
            lblGiaBan.Text = dtr["GiaBan"].ToString()+'$';
            
            //ImageXe.ImageUrl = @"PicTures/SmallImage/" + dtr["Image"].ToString()+".JPG";
            ImageButton1.ImageUrl = @"PicTures/SmallImage/" + dtr["Image"].ToString() + ".JPG";

            //Nhien Lieu
            lblHT_NhienLieu.Text = dtr["HeThongNap"].ToString();
            lblNhienLieu.Text = dtr["NhienLieu"].ToString();

            //Hop So
            lbl_HopSo.Text = dtr["HopSo"].ToString();
            lblHopSo.Text = dtr["HopSo"].ToString();
            lblDanDong.Text = dtr["DanDong"].ToString();
            lblMucTieuThu.Text = dtr["MucTieuThuNhienLieu"].ToString();

            //tui khi an toan
            Image2.ImageUrl = @"Pictures/check_" + dtr["DanhChoNguoiLai"].ToString() + ".gif";
            Image3.ImageUrl = @"Pictures/check_" + dtr["PhiaTruoc"].ToString() + ".gif";
            Image4.ImageUrl = @"Pictures/check_" + dtr["PhiaSau"].ToString() + ".gif";
            Image5.ImageUrl = @"Pictures/check_" + dtr["HaiBen"].ToString() + ".gif";
            Image6.ImageUrl = @"Pictures/check_" + dtr["PhiaTren"].ToString() + ".gif";
            
            //Phanh dieu khien
            Image1.ImageUrl = @"Pictures/check_" + dtr["ChongBoCung"].ToString() + ".gif";
            Image7.ImageUrl = @"Pictures/check_" + dtr["PhanBoLuc"].ToString() + ".gif";
            Image8.ImageUrl = @"Pictures/check_" + dtr["TroLuc"].ToString() + ".gif";
            Image9.ImageUrl = @"Pictures/check_" + dtr["TuDongCanBang"].ToString() + ".gif";
            Image10.ImageUrl = @"Pictures/check_" + dtr["DieuKhien"].ToString() + ".gif";
            Image11.ImageUrl = @"Pictures/check_" + dtr["HoTro"].ToString() + ".gif";
            Image12.ImageUrl = @"Pictures/check_" + dtr["KiemSoatTruot"].ToString() + ".gif";

            //Khoa chong trom
            Image13.ImageUrl = @"Pictures/check_" + dtr["ChotCua"].ToString() + ".gif";
            Image14.ImageUrl = @"Pictures/check_" + dtr["KhoaTuDong"].ToString() + ".gif";
            Image15.ImageUrl = @"Pictures/check_" + dtr["KhoaTuXa"].ToString() + ".gif";
            Image16.ImageUrl = @"Pictures/check_" + dtr["KhoaDongCo"].ToString() + ".gif";
            Image17.ImageUrl = @"Pictures/check_" + dtr["BaoTrom"].ToString() + ".gif";

            //thong so khac
            Image18.ImageUrl = @"Pictures/check_" + dtr["DenSuongMu"].ToString() + ".gif";
            Image19.ImageUrl = @"Pictures/check_" + dtr["DenCanhBaoDayAnToan"].ToString() + ".gif";
            Image20.ImageUrl = @"Pictures/check_" + dtr["DenPhanhPhu"].ToString() + ".gif";

            // Thong so ky thuat
            Image21.ImageUrl = @"Pictures/check_" + dtr["ThietBiDinhVi"].ToString() + ".gif";
            Image22.ImageUrl = @"Pictures/check_" + dtr["CuaSoNoc"].ToString() + ".gif";
            Image23.ImageUrl = @"Pictures/check_" + dtr["KinhChinhDien"].ToString() + ".gif";
            Image24.ImageUrl = @"Pictures/check_" + dtr["TayTroLuc"].ToString() + ".gif";
            lbl_Ghe.Text = dtr["Ghe"].ToString();
            Image25.ImageUrl = @"Pictures/check_" + dtr["DieuHoaTruoc"].ToString() + ".gif";
            Image31.ImageUrl = @"Pictures/check_" + dtr["DieuhoaSau"].ToString() + ".gif";
            Image26.ImageUrl = @"Pictures/check_" + dtr["HoTroTuDong"].ToString() + ".gif";
            Image27.ImageUrl = @"Pictures/check_" + dtr["XayKinhSau"].ToString() + ".gif";
            Image28.ImageUrl = @"Pictures/check_" + dtr["QuatKinhPhiaSau"].ToString() + ".gif";
            Image29.ImageUrl = @"Pictures/check_" + dtr["KinhMau"].ToString() + ".gif";
            Image30.ImageUrl = @"Pictures/check_" + dtr["ManHinhLCD"].ToString() + ".gif";
            lbl_Audio.Text = dtr["ThietBiGiaiTri"].ToString();
            lbl_TBKhac.Text = dtr["ThietBiKhac"].ToString();

            //kich thuoc trong luong
            lbl_KichThuoc.Text = dtr["DaiRongCao"].ToString();
            lbl_ChieuDai.Text = dtr["ChieuDaiCoSo"].ToString();
            lbl_ChieuRong.Text = dtr["ChieuRongCoSo"].ToString();
            lbl_TrongLuong.Text = dtr["TrongLuong"].ToString();
            lbl_DungTich.Text = dtr["DungTichBinhNhienLieu"].ToString();

            //Dong co
            lbl_DongCo.Text = dtr["DongCo"].ToString();
            lbl_KieuDC.Text = dtr["KieuDongCo"].ToString();
            lbl_DungTichXL.Text = dtr["DungTichXiLanh"].ToString();

            //Phanh - Giam xoc - Lop
            lbl_Phanh.Text = dtr["Phanh"].ToString();
            lbl_GiamXoc.Text = dtr["GiamXoc"].ToString();
            lbl_LopXe.Text = dtr["LopXe"].ToString();
            lbl_VanhXe.Text = dtr["VanhMamXe"].ToString();

            //Chi Tiet
            txtChiTietNoiThat.Text = dtr["CTNoiThat"].ToString();
            txtChiTietNgoaiThat.Text = dtr["CTNgoaiThat"].ToString();
            txtChiTietTBiAN.Text = dtr["CTThietBiAnNinh"].ToString();
        }

        // lấy tên hãng chế tạo
        string sqlHang = "select TenHang from hangxe where MaHangXe='" + maHang + "'";
        DataTable dtHang = DataBase.GetDataTable(sqlHang);
        foreach (DataRow dtr in dtHang.Rows)
        {
            lblHangCheTao.Text = dtr["TenHang"].ToString();
        }

        // lấy tên model
        string sqlModel = "select Model from model where ModelId = '" + modelId + "'";
        DataTable dtmodel = DataBase.GetDataTable(sqlModel);
        foreach (DataRow dtr in dtmodel.Rows)
        {
            lblDoiXe.Text = dtr["Model"].ToString();
        }
    }
    protected void btnCartAdd_Click(object sender, ImageClickEventArgs e)
    {
        ShoppingCart cart = (ShoppingCart)Session["ShoppingCart"];

        ImageButton btn = (ImageButton)sender;
        string maxe = lbl_MaXe.Text;
        cart.Add(maxe, 1);

        //ASP.masterpage_master master = (ASP.masterpage_master)this.Master;
        //master.RefreshShoppingCartInfo();
        MasterPage master = (MasterPage)this.Master;
        master.RefreshShoppingCartInfo();
    }
}
